package demo01;

class Animal{
    public String name;
    public int age;

    public Animal(String name, int age) {
        this.name = name;
        this.age = age;
    }

    public void eat(){
        System.out.println(this.name+"正在吃东西");
    }
}

class Dog extends Animal{
    public Dog(String name,int age){
        super(name,age);
        this.name = name;
    }
    public void eat(){
        System.out.println(this.name+"正在吃狗粮");
    }
}

class Bird extends Animal{
    public Bird(String name,int age){
        super(name,age);
        this.name = name;
    }
    public void eat(){
        System.out.println(this.name+"正在吃虫子");
    }
    public void fly(){
        System.out.println(this.name+"正在飞");
    }
}
public class Test01 {
    public static void main(String[] args) {
//        Animal animal = new Dog("wangwang",1);
//        animal.eat();
        Animal animal1 = new Dog("wwww",2);
        if (animal1 instanceof Bird){
//            不是所有的动物都是鸟
            Bird bird = (Bird) animal1;
            bird.fly();
        }else {
            System.out.println("animal1 不是 Bird类型，向下转型需要判断");
            System.out.println("");
        }
    }

}
